Implement feedback controller for redemption rate#142
Open
3esmit wants to merge 2 commits into
Open
Conversation
…s for redemption rate feedback controller - Added `initialize_redemption_controller` and `update_redemption_controller` functions to manage redemption rate feedback. - Introduced `RedemptionController` struct to maintain state for redemption rates. - Updated `Cargo.toml` and `Cargo.lock` to include `twap_oracle_core` dependency. - Modified integration tests to cover new redemption controller functionality.
There was a problem hiding this comment.
Pull request overview
Implements an autonomous redemption-rate feedback controller (P/PI) that derives a signed redemption rate from an oracle market price vs. the current redemption price, with clamping and stale-oracle pausing behavior. This adds the required on-chain controller state + PDA helpers, guest instruction handlers, and integration tests to exercise initialize/update flows.
Changes:
- Add
RedemptionControlleraccount type, gain scaling constant, and PDA helpers; extend Stablecoin instruction enum with initialize/update controller instructions. - Implement host-side controller initialization + update logic using oracle price feeds with staleness checks, error integration clamping, and redemption rate clamping.
- Add guest handlers that constrain outputs to the supplied
current_timestamp, plus integration tests and requiredtwap_oracle_coredependencies/IDL updates.
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| programs/stablecoin/src/redemption_controller.rs | New host implementation + unit tests for controller init/update and controller math. |
| programs/stablecoin/src/lib.rs | Exposes the new redemption_controller module. |
| programs/stablecoin/methods/guest/src/bin/stablecoin.rs | Adds guest instruction handlers for initialize/update with exact timestamp validity windows. |
| programs/stablecoin/methods/guest/Cargo.lock | Pulls in twap_oracle_core via dependency resolution. |
| programs/stablecoin/core/src/lib.rs | Adds controller account type, gain scale constant, PDA helpers, and instruction variants. |
| programs/stablecoin/Cargo.toml | Adds twap_oracle_core dependency for oracle price decoding. |
| programs/integration_tests/tests/stablecoin.rs | Adds end-to-end test covering controller initialize + update from a price feed. |
| programs/integration_tests/Cargo.toml | Adds twap_oracle_core for integration tests. |
| Cargo.lock | Workspace lockfile updates for new dependency edges. |
| artifacts/stablecoin-idl.json | Updates IDL to include the new instructions and account type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+5
to
+9
| use stablecoin_core::{verify_redemption_controller_and_get_seed, RedemptionController}; | ||
| use token_core::TokenDefinition; | ||
| use twap_oracle_core::OraclePriceAccount; | ||
|
|
||
| const CONTROLLER_GAIN_SCALE_I128: i128 = 1_000_000_000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RedemptionControlleraccount, PDA helpers, and fixed-point gain scale.current_timestampso oracle freshness is tied to execution time.Closes #95.